<?php
namespace Activity;

use Activity\Config\Bootstrap;
use Phalcon\Config\Adapter\Ini;

date_default_timezone_set('Etc/GMT-8');
define('DS', DIRECTORY_SEPARATOR);
define('BASE_PATH', realpath(dirname(__FILE__) . '/../../'));
define('APP_PATH', BASE_PATH . '/Activity/');

$envConfig = new Ini(BASE_PATH . '/.env');
define('ENVIRONMENT', $envConfig['ENVIRONMENT']);

if (defined('ENVIRONMENT')) {
    switch ((ENVIRONMENT)) {
        case 'development':
            error_reporting(E_ALL);
            ini_set('display_errors', 'On');
            break;
        case  'testing':
            error_reporting(E_ALL);
            ini_set('display_errors', 'On');
            break;
        case 'production':
        default:
            error_reporting(0);
            ini_set('display_errors', 'Off');
            break;
    }
}
try {
    include APP_PATH . 'Config/Bootstrap.php';
    $bootstrap = new Bootstrap($envConfig);
    $bootstrap->start();
} catch (\PDOException $ex) {
    echo $ex->getMessage();
} catch (\Exception $ex) {
    if (ENVIRONMENT === 'production') {
        if ($ex instanceof DispatcherException) {
            header('Location: /');
            exit();
        } else {
            echo $bootstrap->response->setStatusCode(500)->sendHeaders()->setContent('<h1>500</h1>')->getContent();
        }
    } else {
        echo $ex->getMessage();
    }
} catch (PhalconException $ex) {
    echo $ex->getMessage();
}
